package com.power.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;


import com.github.pagehelper.PageHelper;
import com.mysql.jdbc.PreparedStatement.ParseInfo;
import com.power.model.jdao.IRoleDao;
import com.power.model.jdao.IUserDao;
import com.power.model.mdao.RoleMapper;
import com.power.model.mdao.UserMapper;
import com.power.model.pojo.Role;
import com.power.model.pojo.User;
/**
 * 用户的登陆     添加  删除  修改
 * @author Administrator
 *
 */
@Service
@Transactional
public class LoginService {
	@Autowired
	UserMapper mapper;
	List<User> list;
	@Autowired
	IUserDao dao;
	@Autowired
	IRoleDao rdao;
	@Autowired
	RoleMapper rmapper;
	User u;
	List<Role> rlist=new ArrayList<Role>();
	List<User> ulist=new ArrayList<User>();
	/**
	 * 用户登陆
	 * @param name
	 * @param pwd
	 * @return
	 */
	public User login(String name,String pwd) {
		return mapper.selectByUnameAndPwd(name, pwd);
	}
	public List<User> selectAll(Integer pageNo,Integer pageSize){
		PageHelper.startPage(pageNo, pageSize);
		list=mapper.selectAll();
		return list;
	}


	public void addUser(User u){
	
	dao.save(u);
	}



	public List<User> selectByRId(Integer rid,Integer pageNum,Integer pageSize){
		PageHelper.startPage(pageNum, pageSize);
		list=mapper.selectByRId(rid);
		return list;
	}

	/**
	 * 修改用户的启用状态
	 * @param uid
	 * @param isstatus
	 */
	public void updateUser(Integer uid,Integer isstatus) {
		mapper.updateUser(uid, isstatus);
	}
	public void updateUserAll(User user) {
	dao.save(user);

	}


	public List<User> selectUserBynameAndIS(String name,Integer isstatus,Integer pageNo,Integer pageSize){
		PageHelper.startPage(pageNo, pageSize);
		list=mapper.selectUserBynameAndIS(name, isstatus);
		return list;
	}
	public List<User> selectByuserName(String uname){
		return mapper.selectByuserName(uname);
	}
	/**
	 * 查询角色为巡检员的用户
	 * @return
	 */
	public List<User> selectRoleByxunjian(){
		return mapper.selectRoleByxunjian();
	}
}


